<template>
  <div class="info">
    <h3>基本资料</h3>
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="登录名称">
            <el-input v-model="form.username" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="用户昵称" prop="nickname">
            <el-input v-model="form.nickname"></el-input>
        </el-form-item>
        <el-form-item label="用户邮箱" prop="email">
            <el-input v-model="form.email"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submit">提交修改</el-button>
            <el-button @click="reset">重置</el-button>
        </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getUserInfoAPI } from '@/api/index'
import { uodateUserInfo } from '@/api/user'
export default {
  data () {
    return {
      form: {
        nickname: '', // 用户昵称
        username: '', // 登录昵称
        email: '' // 用户邮箱
      },
      rules: {
        nickname: [
          { required: true, message: '请输入用户名称', trigger: 'blur' }
        ],
        email: [
          { required: true, message: '请输入用户邮箱', trigger: 'blur' }
        ]
      }
    }
  },
  created () {
    this.getInfo()
  },
  methods: {
    // 获取用户数据
    async getInfo () {
      const res = await getUserInfoAPI()
      this.form = res.data
    },
    // 重置表单
    reset () {
      this.$refs.form.resetFields()
    },
    // 提交表单
    async submit () {
      const res = await uodateUserInfo(this.form)
      console.log(res)
    }
  }
}
</script>

<style lang="less" scoped>
.info {
    h3 {
        padding: 50px;
    }
    .el-form {
        margin-top: 20px;
        margin-left: 20px;
        /deep/ .el-input__inner {
            width: 500px;
        }
    }
}
</style>
